package cn.ml.sboot11.pojo.vo;

import lombok.extern.slf4j.Slf4j;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

@Slf4j
public class CountDown {

    public static long mss = 60 * 60 * 24;// 21599
    public static String mydate = "2022-04-08"; //手动设置元旦时间

    public void time(long mss,String date) throws InterruptedException {

        while (mss > 0){
            mss--;
            try {
                Thread.sleep(1000);
                long days = mss / (60 * 60 * 24);

                long hours = (mss % (60 * 60 * 24)) / (60 * 60);

                long minutes = (mss % (60 * 60)) / (60);

                long seconds = (mss % 60);

                if (days == 0 && hours == 0 && minutes == 0 && seconds == 0){
                    break;
                }
                log.info("距离"+ date +"还有" + days + "天" + hours + "小时" + minutes + "分钟" + seconds + "秒");
            } catch (InterruptedException e) {
                Thread.sleep(1000);
                e.printStackTrace();
            }

        }
        log.info("输入的日期已经过去了，请重新输入！！！");
    }

    public void scheduleJob() throws ParseException, InterruptedException {

        SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd");
        //手动输入
        /*
        Scanner input = new Scanner(System.in);
        System.out.println("请手动输入时间，格式为：yyyy-MM-dd");
        myDate = input.next();
        */

        Date date = sdf.parse(mydate);
        long time = date.getTime();
        long timeNow = System.currentTimeMillis();// new Date()为获取当前系统时间，也可使用当前时间戳
        mss = (time - timeNow)/1000;
        time(mss,mydate);
    }
    public static void main(String[] args) throws ParseException, InterruptedException {
    CountDown countDown = new CountDown();
    countDown.scheduleJob();






    }

}
